﻿
namespace KatakPresentationLayer.Web
{
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.ComponentModel.DataAnnotations;
    using System.Linq;
    using System.Web.Ria;
    using System.Web.Ria.Data;
    using System.Web.DomainServices;
    using System.Data;
    using System.Web.DomainServices.LinqToEntities;


    // Implements application logic using the LoliFakulltetEntities context.
    // TODO: Add your application logic to these methods or in additional methods.
    [EnableClientAccess()]
    public class KataService : LinqToEntitiesDomainService<LoliFakulltetEntities>
    {

        // TODO: Consider
        // 1. Adding parameters to this method and constraining returned results, and/or
        // 2. Adding query methods taking different parameters.
        public IQueryable<Teacher> GetTeachers()
        {
            return this.Context.Teachers;
        }
        public IQueryable<Teacher> GetTeachersByName(string name)
        {
            return this.Context.Teachers.Where(c=> c.Name.Contains(name));
        }

        public void InsertTeachers(Teacher teachers)
        {
            this.Context.AddToTeachers(teachers);
        }

        public void UpdateTeachers(Teacher currentTeachers)
        {
            this.Context.AttachAsModified(currentTeachers, this.ChangeSet.GetOriginal(currentTeachers));
        }

        public void DeleteTeachers(Teacher teachers)
        {
            if ((teachers.EntityState == EntityState.Detached))
            {
                this.Context.Attach(teachers);
            }
            this.Context.DeleteObject(teachers);
        }
        public IQueryable<UserData> GetUserData()
        {
            return this.Context.UserDatas;
        }
        public IQueryable<UserData> GetUserDataByName(string username, string password)
        {
            return this.Context.UserDatas.Where(c => c.Username == username && c.Password == password);
        }

        public void InsertUsers(UserData users)
        {
            this.Context.AddToUserDatas(users);
        }

        public void UpdateUser(UserData currentUser)
        {
            this.Context.AttachAsModified(currentUser, this.ChangeSet.GetOriginal(currentUser));
        }

        public void DeleteTeachers(UserData currentUser)
        {
            if ((currentUser.EntityState == EntityState.Detached))
            {
                this.Context.Attach(currentUser);
            }
            this.Context.DeleteObject(currentUser);
        }
    }
}


